/**
 * 
 */
package br.srv.full.virtual.faces.manager.services;

import javax.naming.InitialContext;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import br.srv.full.virtual.engine.users.PersonsManager;
import br.srv.full.virtual.engine.users.PersonsManagerRemote;

/**
 * @author Delfino
 * 
 */
public class ServiceLocator {
	private static final Log log = LogFactory.getLog(ServiceLocator.class);

	public static <service> service getService(String p_serviceName) {
		service obj = null;
		try {
			InitialContext initialCtx = new InitialContext();

			log.info("Inicializando");
			log.info(initialCtx);
			log.info("Usando initialCTX");
			obj = (service) initialCtx.lookup(p_serviceName);
			log.info(obj.getClass().getInterfaces());
		} catch (Exception e) {
			log.warn(e);
			e.printStackTrace();
		}

		return obj;
	}

	public static <service> service getService(Class<service> p_serviceClass) {
		service obj = null;
		obj = getService(p_serviceClass, "remote");
		return obj;

	}

	/**
	 * @param p_serviceClass
	 * @param p_sufixo
	 * @return
	 */
	public static <service> service getService(Class<service> p_serviceClass, String p_sufixo) {
		service obj = null;
		try {
			InitialContext initialCtx = new InitialContext();

			log.info("Inicializando");
			log.info(initialCtx);
			log.info("Usando initialCTX");
			obj = (service) initialCtx.lookup(p_serviceClass.getSimpleName() + "/" + p_sufixo);
			log.info(obj.getClass().getInterfaces());
			
		} catch (Exception e) {
			log.warn(e);
			e.printStackTrace();
		}

		return obj;
	}

}
